package com.heima.search.config;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Data
@Configuration
@Slf4j
@ConfigurationProperties(prefix = "elasticsearch")
public class ESConfig {
    private String host;
    private int port;
    @Bean
    public RestHighLevelClient client()
    {
        log.info("es :  host: {}   port: {}",host,port);
        return new RestHighLevelClient(RestClient.builder(new HttpHost(host,port)));
    }
}
